package git.bds.nyc.admin.convert;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @author 成大事
 * @since 2023/1/11 9:52
 */
public class TypeConvert implements Converter<Integer> {
    /**
     * 支持java类型密钥
     *
     * @return {@link Class}
     */
    @Override
    public Class supportJavaTypeKey() {return Integer.class;}

    /**
     * 支持excel类型键
     *
     * @return {@link CellDataTypeEnum}
     */
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {return CellDataTypeEnum.STRING;}

    /**
     * 转换为java数据
     *
     * @param readCellData         读取单元格数据
     * @param excelContentProperty excel内容属性
     * @param globalConfiguration  全局配置
     * @return {@link Integer}
     * @throws Exception 例外
     */
    @Override
    public Integer convertToJavaData(ReadCellData readCellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String stringValue = readCellData.getStringValue();
        if (stringValue == null) {
            throw new RuntimeException("性别填写为空");
        }
        if ("男".equals(stringValue)) {
            return 1;
        }
        return 0;
    }

    /**
     * 转换为excel数据
     *
     * @param s                    s
     * @param excelContentProperty excel内容属性
     * @param globalConfiguration  全局配置
     * @return {@link WriteCellData}
     * @throws Exception 例外
     */
    @Override
    public WriteCellData convertToExcelData(Integer s, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if	(s == 0){
            return new WriteCellData("农户初级");
        }else if(s == 1){
            return new WriteCellData("公司初级");
        }else if(s == 2){
            return new WriteCellData("公司加工");
        }else if(s == 3){
            return new WriteCellData("农户需求");
        }else{
            return new WriteCellData("公司需求");
        }
    }

}